﻿using System;
using System.Collections.Generic;
using AuthRes = BotonJXC.Entity.AuthRes;

namespace BotonJXC.DAO
{
    public class AuthResDAO : NHibernateDao<AuthRes, int>
    {
        public IList<AuthRes> FindByUserId(int userId)
        {
            string hql = "from AuthRes a WHERE a.AuthResId IN(SELECT b.AuthRes.AuthResId FROM RoleAuthRes b where b.Role.RoleId IN(SELECT c.Role.RoleId FROM Account c where c.UserId=?)) ORDER BY a.AuthResPath";
            
            return base.Find(hql, userId);
        }

        public IList<AuthRes> FindByRoleId(int roleId)
        {
            string hql = "from AuthRes a WHERE a.AuthResId IN(SELECT b.AuthRes.AuthResId FROM RoleAuthRes b where b.Role.RoleId =?) ORDER BY a.AuthResPath";

            return base.Find(hql, roleId);
        }
    }
}
